﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ElingOA6_Admin_DSJCJ.BLL
{
    /// <summary>
    /// 
    /// </summary>
    public partial class OfficeItemDeptCount
    {
        /// <summary>
        /// Dal定义的便利
        /// </summary>
        private readonly DAL.OfficeItemDeptCount dal = new DAL.OfficeItemDeptCount();

        /// <summary>
        /// 
        /// </summary>
        /// <param name="deptNo"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns></returns>
        public List<Model.OfficeItemDeptCount> GetAllList(string deptNo, string startDate, string endDate)
        {
            DataSet ds = dal.GetAllList(deptNo, startDate, endDate);
            return DataTableToListOfficeItemDeptCount(ds.Tables[0]);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="deptNo"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns></returns>
        public List<Model.OfficeItemDeptCount> GetAllList1(string deptNo, string startDate, string endDate)
        {
            DataSet ds = dal.GetAllList1(deptNo, startDate, endDate);
            return DataTableToListOfficeItemDeptCount1(ds.Tables[0]);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="deptNo"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns></returns>
        public DataSet GetAll(string deptNo, string startDate, string endDate)
        {
            return dal.GetAllList(deptNo, startDate, endDate);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public List<Model.OfficeItemDeptCount> DataTableToListOfficeItemDeptCount1(DataTable dt)
        {
            List<Model.OfficeItemDeptCount> modelList = new List<Model.OfficeItemDeptCount>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.OfficeItemDeptCount model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.OfficeItemDeptCount();
                    if (dt.Rows[n]["FItemNo"] != null)
                    {
                        model.FItemNo = dt.Rows[n]["FItemNo"].ToString();
                    }
                    if (dt.Rows[n]["FItemRequisitionApplyID"] != null && dt.Rows[n]["FItemRequisitionApplyID"].ToString() != "")
                    {
                        model.FItemRequisitionApplyID = int.Parse(dt.Rows[n]["FItemRequisitionApplyID"].ToString());
                    }
                    if (dt.Rows[n]["FItemNo"] != null)
                    {
                        model.FItemNo = dt.Rows[n]["FItemNo"].ToString();
                    }
                    if (dt.Rows[n]["FApplyDeptNo"] != null)
                    {
                        model.FApplyDeptNo = dt.Rows[n]["FApplyDeptNo"].ToString();
                    }
                    if (dt.Rows[n]["FDeptName"] != null)
                    {
                        model.FDeptName = dt.Rows[n]["FDeptName"].ToString();
                    }
                    if (dt.Rows[n]["FApplyEmplNo"] != null)
                    {
                        model.FApplyEmplNo = dt.Rows[n]["FApplyEmplNo"].ToString();
                    }
                    if (dt.Rows[n]["FEmpName"] != null)
                    {
                        model.FEmpName = dt.Rows[n]["FEmpName"].ToString();
                    }
                    if (dt.Rows[n]["FItemName"] != null)
                    {
                        model.FItemName = dt.Rows[n]["FItemName"].ToString();
                    }
                    if (dt.Rows[n]["FItemSpec"] != null)
                    {
                        model.FItemSpec = dt.Rows[n]["FItemSpec"].ToString();
                    }
                    if (dt.Rows[n]["FQty"] != null && dt.Rows[n]["FQty"].ToString() != "")
                    {
                        model.FQty = decimal.Parse(dt.Rows[n]["FQty"].ToString());
                    }
                    if (dt.Rows[n]["FAmount"] != null && dt.Rows[n]["FAmount"].ToString() != "")
                    {
                        model.FAmount = decimal.Parse(dt.Rows[n]["FAmount"].ToString());
                    }
                    if (dt.Rows[n]["FPrice"] != null && dt.Rows[n]["FPrice"].ToString() != "")
                    {
                        model.FPrice = decimal.Parse(dt.Rows[n]["FPrice"].ToString());
                    }
                    if (dt.Rows[n]["FAuditDate"] != null && dt.Rows[n]["FAuditDate"].ToString() != "")
                    {
                        model.FAuditDate = DateTime.Parse(dt.Rows[n]["FAuditDate"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }


        /// <summary>
        ///  获得数据列表
        /// <creator>chenly</creator>
        /// <date>2013-10-11</date>
        /// </summary>
        /// <param name="dt">表</param>
        /// <returns>DataTable</returns>
        public List<Model.OfficeItemDeptCount> DataTableToListOfficeItemDeptCount(DataTable dt)
        {
            List<Model.OfficeItemDeptCount> modelList = new List<Model.OfficeItemDeptCount>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.OfficeItemDeptCount model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.OfficeItemDeptCount();

                    if (dt.Rows[n]["FItemNo"] != null)
                    {
                        model.FItemNo = dt.Rows[n]["FItemNo"].ToString();
                    }
                    if (dt.Rows[n]["FApplyDeptNo"] != null)
                    {
                        model.FApplyDeptNo = dt.Rows[n]["FApplyDeptNo"].ToString();
                    }
                    if (dt.Rows[n]["FDeptName"] != null)
                    {
                        model.FDeptName = dt.Rows[n]["FDeptName"].ToString();
                    }               
                    if (dt.Rows[n]["FItemName"] != null)
                    {
                        model.FItemName = dt.Rows[n]["FItemName"].ToString();
                    }
                    if (dt.Rows[n]["FItemSpec"] != null)
                    {
                        model.FItemSpec = dt.Rows[n]["FItemSpec"].ToString();
                    }
                    if (dt.Rows[n]["fqy"] != null && dt.Rows[n]["fqy"].ToString() != "")
                    {
                        model.fqy = decimal.Parse(dt.Rows[n]["fqy"].ToString());
                    }
                    if (dt.Rows[n]["amount"] != null && dt.Rows[n]["amount"].ToString() != "")
                    {
                        model.amount = decimal.Parse(dt.Rows[n]["amount"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

    }
}
